﻿
using RTW.DAL;
using RTW.OA.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace RTW.OA.Areas.Meeting.Servers
{
    public class EquipmentServers
    {
        private readonly IRepository<meeting_equipment> meeting_equipmentRepository;
        private readonly IRepository<meeting_room> meeting_roomRepository;

        public EquipmentServers()
        {
            meeting_equipmentRepository = new DapperRepository<meeting_equipment>();
            meeting_roomRepository = new DapperRepository<meeting_room>();

        }

        public List<meeting_equipment> GetData()
        {
            var datas = meeting_equipmentRepository.GetAllEnumerable();

            return datas.ToList();
        }

        public meeting_equipment GetModelById(string id)
        {
            return meeting_equipmentRepository.GetById(id);
        }


        internal void Add(meeting_equipment model)
        {
            meeting_equipmentRepository.Insert(model);
        }

        internal void Update(meeting_equipment model)
        {
            meeting_equipmentRepository.Update(model);
        }

        internal void Del(string id)
        {
            meeting_equipmentRepository.DeleteByIds(id);
        }


        internal List<SelectListItem> GetMR_ID()
        {
            List<SelectListItem> tables = new List<SelectListItem>();
            var dstable = meeting_equipmentRepository.SqlWithParamsDynamic("select MR_ID Value,MR_NAME Text from [dbo].[meeting_room]");
            tables.Clear();

            foreach (var dr in dstable)
            {
                string Id = dr.Value.ToString();
                string Title = dr.Text.ToString().Trim();
                tables.Add(new SelectListItem { Value = Id, Text = Title });
            }

            return tables;
        }
        public meeting_room GetMeetingById(int? id)
        {
            return meeting_roomRepository.GetById(id);
        }

    }
}